const mongoose = require('mongoose');

const exerciseSchema = new mongoose.Schema({
  title: {
    type: String,
    required: [true, '题目标题不能为空'],
    trim: true,
    maxlength: [200, '题目标题不能超过200个字符']
  },
  content: {
    type: String,
    required: [true, '题目内容不能为空'],
    trim: true
  },
  type: {
    type: String,
    enum: ['Task1', 'Task2'],
    required: [true, '题目类型不能为空']
  },
  difficulty: {
    type: String,
    enum: ['Easy', 'Medium', 'Hard'],
    default: 'Medium'
  },
  timeLimit: {
    type: Number,
    required: [true, '时间限制不能为空'],
    min: [10, '时间限制不能少于10分钟'],
    max: [60, '时间限制不能超过60分钟']
  },
  wordLimit: {
    type: Number,
    required: [true, '字数要求不能为空'],
    min: [150, '字数要求不能少于150字'],
    max: [300, '字数要求不能超过300字']
  },
  isActive: {
    type: Boolean,
    default: true
  }
}, {
  timestamps: true
});

// 创建索引
exerciseSchema.index({ type: 1, difficulty: 1 });
exerciseSchema.index({ isActive: 1 });

module.exports = mongoose.model('Exercise', exerciseSchema);
